package br.com.escola;

import java.util.HashMap;
import java.util.Map;

import br.com.escola.util.FileUtil;

public class InserirBoleto
{
	public static void main(String[] args)
	{
		try
		{
			Map<String, String> mAlunos = new HashMap<String, String>();
			StringBuffer        sb      = new StringBuffer();
			int                 k       = 0;
			String              unidade = "e:/";
			String              dataArq = "2013-03-13";

			sb.append("<%@page import=\"java.util.Date\"%>\n<%@page import=\"br.com.colegio.dao.BoletoDAO\"%><%\n");

			for (String s : FileUtil.pegaURL(unidade + "_escola/conta-corrente/boletos/boletos" + dataArq + ".csv", "\n").split("\n"))
			{
				String[] c = s.split(";");

				mAlunos.put(c[1], c[0]);

				sb.append("out.print(BoletoDAO.save(\"" + c[3].replaceAll("'", "").trim() + "\",\"" +
							c[2].replaceAll("'", "").trim() + "\"," +
							"new Date(" + (Integer.parseInt(c[4].replaceAll("'", "").trim().split("/")[2]) - 1900) + "," +
								(Integer.parseInt(c[4].replaceAll("'", "").trim().split("/")[1]) - 1) + "," +
								Integer.parseInt(c[4].replaceAll("'", "").trim().split("/")[0]) + ")," +
							"new Date(" + (Integer.parseInt(c[5].replaceAll("'", "").trim().split("/")[2]) - 1900) + "," +
								(Integer.parseInt(c[5].replaceAll("'", "").trim().split("/")[1]) - 1) + "," +
								Integer.parseInt(c[5].replaceAll("'", "").trim().split("/")[0]) + ")," +
							Double.valueOf(c[6].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							Double.valueOf(c[7].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							Double.valueOf(c[8].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							"new Date(" + (Integer.parseInt(c[9].replaceAll("'", "").trim().split("/")[2]) - 1900) + "," +
								(Integer.parseInt(c[9].replaceAll("'", "").trim().split("/")[1]) - 1) + "," +
								Integer.parseInt(c[9].replaceAll("'", "").trim().split("/")[0]) + ")," +
							Double.valueOf(c[10].replaceAll("'", "").trim().replaceAll(",", ".")) + ",\"" +
							c[11].replaceAll("'", "").trim() + "\",\"" +
							c[12].replaceAll("'", "").trim().replaceAll("\\.\\.", ".") + "\"," +
							(!c[14].replaceAll("'", "").trim().equals("") ?
								"new Date(" + (Integer.parseInt(c[14].replaceAll("'", "").trim().split("/")[2]) - 1900) + "," +
									(Integer.parseInt(c[14].replaceAll("'", "").trim().split("/")[1]) - 1) + "," +
									Integer.parseInt(c[14].replaceAll("'", "").trim().split("/")[0]) + "),"
								: "null,") +
							Double.valueOf(c[15].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							Double.valueOf(c[16].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							Double.valueOf(c[17].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							Double.valueOf(c[18].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							(!c[19].replaceAll("'", "").trim().equals("") ?
								"new Date(" + (Integer.parseInt(c[19].replaceAll("'", "").trim().split("/")[2]) - 1900) + "," +
									(Integer.parseInt(c[19].replaceAll("'", "").trim().split("/")[1]) - 1) + "," +
									Integer.parseInt(c[19].replaceAll("'", "").trim().split("/")[0]) + "),\""
								: "null,\"") +
							c[1].replaceAll("'", "").trim() + "\"," +
							Integer.valueOf(c[13].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
							(!c[20].replaceAll("'", "").trim().equals("") ? Integer.valueOf(c[20].replaceAll("'", "").trim()) : 0) + "," +
							(!c[14].replaceAll("'", "").trim().equals("") ? "\"P\"" : "\"A\"") + "," +
							"\"BANCO\") + \"<br>\");\n");

				k++;

				if (k % 100 == 0)
				{
					sb.append("\n%>");
					FileUtil.write(unidade + "_escola/conta-corrente/boletos/carga/insert-boletos-" + dataArq + "_" + k + ".jsp", sb.toString());

					sb = new StringBuffer();
					sb.append("<%@page import=\"java.util.Date\"%>\n<%@page import=\"br.com.colegio.dao.BoletoDAO\"%><%\n");
				}
			}

			if (k % 100 != 0)
			{
				sb.append("\n%>");
				FileUtil.write(unidade + "_escola/conta-corrente/boletos/carga/insert-boletos-" + dataArq + "_" + k + ".jsp", sb.toString());
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
